package com.example.happiness.service.employee.Impl;

import com.example.happiness.constant.Message;
import com.example.happiness.mapper.FeedbackMapper;
import com.example.happiness.mapper.OrderDispatchMapper;
import com.example.happiness.pojo.Feedback;
import com.example.happiness.pojo.OrderDispatch;
import com.example.happiness.pojo.employeevo.EmployAverageScoreVO;
import com.example.happiness.service.employee.EmployFeedbackService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service
public class EmployFeedbackServiceImpl implements EmployFeedbackService {
    @Autowired
    FeedbackMapper feedbackMapper;
    @Autowired
    OrderDispatchMapper orderDispatchMapper;

    public EmployAverageScoreVO getScore(String eid) {
        List<OrderDispatch> orderids = orderDispatchMapper.getOrderid(eid);
        EmployAverageScoreVO employAverageScoreVO = new EmployAverageScoreVO();
        if (orderids.size() != 0) {
            float score = 0;
            long i=0;
            for (OrderDispatch orderid : orderids) {
                Feedback feedback = feedbackMapper.getScore(orderid.getOrderid());
                if (feedback == null) {
                    score = score+ Message.FIVE;
                }else {
                    score = score + feedback.getScore();
                }
                i++;
            }
            employAverageScoreVO.setScore(score/i);
            employAverageScoreVO.setProportion((score/i)/Message.FIVE);
        }
        return employAverageScoreVO;
    }
}
